package com.usain.controller;

import com.usain.pojo.User;
import com.usain.service.UserService;
import jdk.nashorn.internal.ir.annotations.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/user")
@Controller
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/toUser")
    public String toUser(){
        return "addUser";
    }

    @RequestMapping("/insertUser")
    public String insertUser(User user){
        userService.insertUser(user);
        return "redirect:/user/findAll";
    }

    @RequestMapping("findAll")
    public String findAll(Model model){
        List<User> userList = userService.findList();
        System.out.println("==============================");
        model.addAttribute("userList",userList);
        return "index";
    }
    @RequestMapping("deleteId")
    public String deleteId(Integer userId,Model model){
        userService.deleteId(userId);
        return "redirect:/user/findAll";
    }

}
